package com.liugan.magic.utils;

import org.loon.framework.android.game.core.LSystem;
import org.loon.framework.android.game.core.graphics.opengl.LTexture;

import android.util.Log;

import com.liugan.magic.Constants;

public class ImagesUtils {
	//actor使用的
	
	//背景
	public LTexture bg1; 
	public LTexture bg2; 
	public LTexture bg3; 
	public LTexture bg4; 
	public LTexture bg5; 
	//前景
	public LTexture fg1; 
	public LTexture fg2; 
	public LTexture fg3; 
	public LTexture fg4; 
	public LTexture grass_1; 
	public LTexture grass_2; 
	
	//前景石头
	//f_s1 f_s2
	public LTexture f_s1; 
	public LTexture f_s2; 
	
	//前景蘑菇
	//mushroom
	public LTexture f_m1; 
	public LTexture f_m2; 
	
	private static ImagesUtils instance;
	private ImagesUtils(){
		
		//背景
		bg1=new LTexture(Constants.imagespath +"back/bg1.png");
		bg2=new LTexture(Constants.imagespath +"back/bg2.png");
		bg3=new LTexture(Constants.imagespath +"back/bg3.png");
		bg4=new LTexture(Constants.imagespath +"back/bg4.png");
		bg5=new LTexture(Constants.imagespath +"back/bg5.png");
		
		//前景
		fg1=new LTexture(Constants.imagespath +"fore/f1.png");
		fg2=new LTexture(Constants.imagespath +"fore/f2.png");
		fg3=new LTexture(Constants.imagespath +"fore/f3.png");
		fg4=new LTexture(Constants.imagespath +"fore/f4.png");
		
		
		grass_1=new LTexture(Constants.imagespath + "grass/grass_1.png");
		grass_2=new LTexture(Constants.imagespath + "grass/grassend.png");
		
		f_s1=new LTexture(Constants.imagespath +"f_s/f_s1.png");
		f_s2=new LTexture(Constants.imagespath +"f_s/f_s2.png");
		
		f_m1=new LTexture(Constants.imagespath +"mushroom/f_m1.png");
		f_m2=new LTexture(Constants.imagespath +"mushroom/f_m2.png");
		LSystem.gc();
	}
	
	
	public synchronized static ImagesUtils getinstance(){
		if (instance==null){
			instance=new ImagesUtils();
		}
		return instance;
	}
	
	public synchronized void destroy(){
		instance=null;
		LSystem.gc();
	}
	
	public void getLTexture(String LTexturename) {
		//Log.i("bbb", "将要创建"+LTexturename);
		if ("bg1".equals(LTexturename)){
			bg1= new LTexture(Constants.imagespath +"back/bg1.png");
			bg1.loadTexture();
		}
		if ("bg2".equals(LTexturename)){
			bg2=new LTexture(Constants.imagespath +"back/bg2.png");
			bg2.loadTexture();
		}
		if ("bg3".equals(LTexturename)){
			bg3= new LTexture(Constants.imagespath +"back/bg3.png");
			bg3.loadTexture();
		}
		if ("bg4".equals(LTexturename)){
			bg4= new LTexture(Constants.imagespath +"back/bg4.png");
			bg4.loadTexture();
		}
		if ("bg5".equals(LTexturename)){
			bg5= new LTexture(Constants.imagespath +"back/bg5.png");
			bg5.loadTexture();
		}
		if ("fg1".equals(LTexturename)){
			fg1= new LTexture(Constants.imagespath +"fore/f1.png");
			fg1.loadTexture();
		}
		if ("fg2".equals(LTexturename)){
			fg2= new LTexture(Constants.imagespath +"fore/f2.png");
			fg2.loadTexture();
		}
		if ("fg3".equals(LTexturename)){
			fg3= new LTexture(Constants.imagespath +"fore/f3.png");
			fg3.loadTexture();
		}
		if ("fg4".equals(LTexturename)){
			fg4= new LTexture(Constants.imagespath +"fore/f4.png");
			fg4.loadTexture();
		}
	}
	
	public void disLTexture(String LTexturename){
		if ("bg1".equals(LTexturename)){
			bg1.dispose();
			bg1= null;
		}
		if ("bg2".equals(LTexturename)){
			bg2.dispose();
			bg2= null;
		}
		if ("bg3".equals(LTexturename)){
			bg3.dispose();
			bg3= null;
		}
		if ("bg4".equals(LTexturename)){
			bg4.dispose();
			bg4= null;
		}
		if ("bg5".equals(LTexturename)){
			bg5.dispose();
			bg5= null;
		}
		if ("fg1".equals(LTexturename)){
			fg1.dispose();
			fg1= null;
		}
		if ("fg2".equals(LTexturename)){
			fg2.dispose();
			fg2= null;
		}
		if ("fg3".equals(LTexturename)){
			fg3.dispose();
			fg3= null;
		}
		if ("fg4".equals(LTexturename)){
			fg4.dispose();
			fg4= null;
		}
		//LSystem.gc();
	}
}
